﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using DataAccessLayer.Security;
using Common;
namespace DataAccessLayer.DAL
{
    public class ShippingDetailDAL
    {
         /// <summary>
        /// Lay thong tin cua mot buyer bang username
        /// </summary>
        /// <param name="username">Username of user store in DB</param>
        /// <returns>Appropriate user if exists, NULL if not.</returns>
        public static ShippingDetail GetShippingDetailByIDUser(int idUser)
        {
            using (var context = new ReverseAuctionEntities())
            {
                return context.ShippingDetails.SingleOrDefault(u =>u.UserID == idUser);
            }
        }
        /// <summary>
        /// Cap nhat thong tin mot shippingDetail
        /// </summary>
        /// <param name="user">shippingDetail to update</param>
        public static void UpdateShippingDetail(ShippingDetail shipping)
        {
            using (var context = new ReverseAuctionEntities())
            {
                context.ShippingDetails.Attach(shipping);
                context.ObjectStateManager.ChangeObjectState(shipping, System.Data.EntityState.Modified);
                context.SaveChanges();
            }
        }
    }
}
